package com.netty.nio.zerocopy;

import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class OldIOClient {

    public static void main(String[] args) throws IOException {
        //生成一个socket
        Socket socket = new Socket("127.0.0.1", 7001);
        //Socket socket = new Socket("localhost", 7001);
        String fileName = "protoc-3.6.1-win32.zip";
        InputStream inputStream = new FileInputStream(fileName);
        DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
        byte[] byteArray = new byte[4096];
        long readCount;
        long totle = 0;
        long star = System.currentTimeMillis();
        while ((readCount =inputStream.read(byteArray)) >= 0){
            totle += readCount;
            dataOutputStream.write(byteArray);
        }
        long end = System.currentTimeMillis();
        System.out.println("已发送总数:"+totle+"耗时:"+(end-star));
        dataOutputStream.close();
        inputStream.close();
        socket.close();
    }
}
